package link;

public class deleteLink {
    public ListNode removeNthFromEnd(ListNode head,int n) {
        ListNode result = new ListNode(0);
        result.next = head;
        ListNode first = result;
        ListNode second = result;
        for (int i = 1; i <= n + 1; i++) {
            first = first.next;

        }
        while(first!=null){
            first=first.next;
            second=second.next;
        }
        second.next=second.next.next;
        return result.next;
    }
}
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
        val = x;
    }
}
